﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QldtSdh.DAL.Models;

namespace QldtSdh.BLL
{
    public partial class BizChiTietMay
    {
        public static void GetStatisCanhBao(string maChiTietMay, out int quaHan, out int trongHan, out int truocHan, string manv = "")
        {
            using (var db = CEMS4UG_DHKHContext.GetContext())
            {
                var lsCTMDPC = db.PhanCongBaoTriDbSet.Where(e => e.MaNhanVien == manv).Select(e => e.MaChiTietMay).ToList();
                var ls = db.LichBaoTriDbSet.Where(e =>
                    e.ChiTietMay.MaChiTietMay == maChiTietMay &&
                    (string.IsNullOrEmpty(manv) ? true : lsCTMDPC.Contains(e.MaChiTietMay)))
                    .ToList();
                trongHan = ls.Count(e => DateTime.Now.Date.Subtract(e.NgayBaoTri.Date).Days == 0);
                quaHan = ls.Count(e => DateTime.Now.Date.Subtract(e.NgayBaoTri.Date).Days > 0);
                var cb = int.Parse(BizAppConfig.GetDSCanhBaoMobile());
                truocHan = ls.Count(e => DateTime.Now.Date.Subtract(e.NgayBaoTri.Date).Days < cb);
            }
        }
        public static List<ChiTietMay> GetList(string maBoPhanMay)
        {
            using (var db = CEMS4UG_DHKHContext.GetContext())
            {
                return db.ChiTietMayDbSet.Where(e => e.MaBoPhanMay == maBoPhanMay).OrderBy(e => e.TenChiTietMay).ToList();
            }
        }
    }
}
